package com.hejia.bulbul.controller;

import com.hejia.alauda.entity.Parameter;
import com.hejia.alauda.service.ConfigureService;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * 
 * 设置/支付网关设置
 *
 *
 * Created by showone on 2014 下午5:12:35.
 */
@Controller
@RequestMapping("setting/paygate")
public class SettingPaygateController extends BaseController {

	@Resource
	private ConfigureService parameterService;

	@RequestMapping(value = "", method = RequestMethod.GET)
	public String list(ModelMap model) {
		Parameter param = parameterService
				.getParameter(Parameter.Category.Paygate);

		model.put("param", param);
		return "/setting/paygate";
	}

	@RequestMapping(value = "update", method = RequestMethod.POST)
	public String update(@RequestParam String paygate, ModelMap model) {
		Parameter param = parameterService
				.getParameter(Parameter.Category.Paygate);
		param.setValue(paygate);
		if ("llpay".equals(paygate)) {
			param.setMemo("连连支付");
		} else if ("upop".equals(paygate)) {
			param.setMemo("银联支付");
		} else if ("cpsfj".equals(paygate)) {
			param.setMemo("银联收付捷支付");
		}
		if (parameterService.updateParameter(param)) {
			model.put("status", STATUS_SUCCESS);
			model.put("msg", "修改成功!");
		} else {
			model.put("status", STATUS_FAILD);
			model.put("msg", "修改失败!");
		}

		return list(model);
	}
}
